From 47d9bf8b4c555ff7f6d580920f5e6c864a76a7bc Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Wed, 18 Jun 2014 12:01:54 -0700 Subject: [PATCH] Provide more context on process errors When printing an error for a failed process execution, the stdout/stderr are included for inspection. --- src/cargo/util/errors.rs | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/src/cargo/util/errors.rs b/src/cargo/util/errors.rs index 771d1dc36..03c38753e 100644 --- a/src/cargo/util/errors.rs +++ b/src/cargo/util/errors.rs @@ -143,18 +143,30 @@ impl Show for ProcessError { Some(ExitStatus(i)) | Some(ExitSignal(i)) => i.to_str(), None => "never executed".to_str() }; - write!(f, "{} (status={})", self.msg, exit) + try!(write!(f, "{} (status={})", self.msg, exit)); + match self.output { + Some(ref out) => { + match str::from_utf8(out.output.as_slice()) { + Some(s) if s.trim().len() > 0 => { + try!(write!(f, "\n--- stdout\n{}", s)); + } + Some(..) | None => {} + } + match str::from_utf8(out.error.as_slice()) { + Some(s) if s.trim().len() > 0 => { + try!(write!(f, "\n--- stderr\n{}", s)); + } + Some(..) | None => {} + } + } + None => {} + } + Ok(()) } } impl CargoError for ProcessError { - fn description(&self) -> String { - let exit = match self.exit { - Some(ExitStatus(i)) | Some(ExitSignal(i)) => i.to_str(), - None => "never executed".to_str() - }; - format!("{} (status={})", self.msg, exit) - } + fn description(&self) -> String { self.to_str() } fn detail(&self) -> Option { self.detail.clone() -- 2.30.2